<template>
    <div class="reflect_page">
      <van-nav-bar
        title="总资本"
        left-arrow
        @click-left="$router.back()"
        left-text="返回"
      />
      <!-- <com-header :comHeaderObj="headerObj"></com-header> -->

      <van-form @submit="onSubmit">
        <van-field autocomplete="off"
            v-model="price"
            name="转入钱包"
            label="转入钱包 ¥"
            placeholder="请输入转入金额"
            :rules="[{ required: true, message: '请输入转入金额' }]"
        />
        <van-field autocomplete="off"
            v-model="password"
            type="password"
            name="支付密码"
            label="支付密码"
            placeholder="请输入支付密码"
            :rules="[{ required: true, message: '请填写支付密码' }]"
        />
        <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
        </van-form>
    </div>
</template>

<script>
  import {Toast} from 'vant';
import comHeader from '../../components/comHeader';
  const cashWay = {
    card: '银行卡',
    wechat: '微信',
    qq: 'QQ',
    alipay: '支付宝',
  };

  export default {
    name: 'reflect',
    data(){
      return{
        cashWay,
        money:'',
        intoWay:'',
        name:'',
        account:'',
        payPwd: '',
        pattern:  /^[0-9]+(\.[0-9]{0,2})?$/,
        cashOutSign: '',
        headerObj: {
          title: '总资本',
          money: 0,
          leftBtnText: '提现',
          leftBtnPath: '/cash/reflect',
          middleBtnText: '总记录',
          middleBtnPath: '/groupStock/generalRecord',
          rightBtnText: '资本充值',
          rightBtnPath: '/reCharge',
          // 提现标识：申请借支的页面
          cashOutSign: 'groupStock',
        },
      }
    },
    components: {
      comHeader
    },
    created(){
      if (this.$route.params.id){
        this.cashOutSign = this.$route.params.id
      } else {
        //this.$router.back()
      }
    },

    methods:{
      onSubmit(values){
        const params = {
          account: values.account,
          cashname: values.name,
          money:  values.money*1000,
          paypassword: this.$Base64.encode(this.$md5(values.payPwd) + this.$md5('jinpin888')),
          acctype: values.intoWay,
        };

        // 局部变量
        let url
        switch (this.cashOutSign) {
          case 'recommendPersons':
            url = '';
            this._cashOutSign_all(url, params);
            break;
          case 'lendMoney':
            url = '';
            this._cashOutSign_all(url, params);
            break;
          case 'wage':
            url = '';
            this._cashOutSign_all(url, params);
            break;
          default:
            url = '/api/stock/cash';
            this._cashOutSign_all(url, params);
        }
      },

      async _cashOutSign_all(url, params){
        if (url){
          const res =  await this.$api.stock.reqDrawCash(url, params)
          if (res.code === 200){
            Toast(res.data)
            await this.$router.back()
          }
        } else {
          Toast('提现参数有误，请退出登录重试！')
        }

      },




    }
  }
</script>

<style scoped>

</style>
